﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import flash.filters.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import Display.hud.*;

    public class HUDXPComponent extends HUDComponent {

        public var m_xpSliderAsset:Class;
        public var m_xpSlider:HUDXPComponent_m_xpSliderAsset;
        public var m_xpText:JTextField;
        private var m_xpHolder:JPanel;
        public var m_levelText:JTextField;
        private var m_level:int;

        public function HUDXPComponent(_arg1:Function=null){
            this.m_xpSliderAsset = HUDXPComponent_m_xpSliderAsset;
            this.m_xpSlider = (new HUDXPComponent_m_xpSliderAsset() as HUDXPComponent_m_xpSliderAsset);
            super();
            this.m_level = 1;
        }
        override protected function buildComponent():void{
            m_jPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT, 0);
            var _local1:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 16, 0xFFFFFF, true, false, false, null, null, TextFormatAlign.CENTER);
            var _local2:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 15, 0xFFFFFF, true, false, false, null, null, TextFormatAlign.CENTER);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_xpHolder = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            ASwingHelper.setSizedBackground(this.m_xpHolder, this.m_xpSlider);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            _local4.setBorder(new EmptyBorder(null, new Insets(13, 8, 0, 0)));
            this.m_xpHolder.append(_local4);
            this.m_xpText = ASwingHelper.makeTextField("0", EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 0xFFFFFF, 0, _local1);
            this.m_xpText.filters = [new GlowFilter(0, 0.5, 3, 3, 10)];
            this.m_xpText.setBorder(new EmptyBorder(null, new Insets(3)));
            var _local5:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER);
            _local5.append(this.m_xpText);
            _local5.setPreferredWidth(84);
            var _local6:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 0);
            _local6.setPreferredWidth(40);
            ASwingHelper.setEasyBorder(_local6, 0, 2, 12);
            this.m_levelText = ASwingHelper.makeTextField("0", EmbeddedArt.TITLE_FONT, 18, EmbeddedArt.yellowTextColor, 0, _local2);
            this.m_levelText.filters = [new GlowFilter(0, 0.5, 3, 3, 10)];
            _local6.append(this.m_levelText);
            _local4.append(_local5);
            _local4.append(ASwingHelper.horizontalStrut(2));
            _local4.append(_local6);
            _local3.append(this.m_xpHolder);
            _local3.setBorder(new EmptyBorder(null, new Insets(1)));
            m_jPanel.append(_local3);
        }
        override protected function attachToolTip():void{
            m_toolTip = new ToolTip();
            m_toolTip.attachToolTip(this);
            m_toolTip.hideCursor = true;
        }
        override protected function setCounter():void{
            m_counter = new HUDCounter(function (_arg1:Number):void{
                m_xpText.setText(String(int(_arg1)));
                updateCounter(Global.player.xp);
            });
            this.m_xpText.setText(String(Global.player.xp));
            refresh(false);
        }
        override public function updateCounter(... _args):void{
            var _local12:Boolean;
            var _local13:int;
            var _local14:XML;
            var _local15:Number;
            var _local2:int = _args[0];
            var _local3:XMLList = Global.gameSettings.getLevelsXML().level;
            var _local4:int = this.m_level;
            var _local5:Number = 0;
            var _local6:Number = 0;
            var _local7:Number = 0;
            if (_local2 > 0){
                _local12 = false;
                _local13 = _local4;
                while (_local13 < _local3.length()) {
                    _local14 = _local3[_local13];
                    _local15 = Number(_local3[(_local13 - 1)].@requiredXP);
                    _local6 = Number(_local3[_local13].@requiredXP);
                    _local7 = (_local6 - _local2);
                    _local5 = ((_local6 - _local2) / (_local6 - _local15));
                    if (_local14.@requiredXP <= _local2){
                        _local4 = (_local13 + 1);
                        _local12 = true;
                    } else {
                        break;
                    };
                    _local13++;
                };
            } else {
                _local4 = 1;
                _local5 = 1;
            };
            if (_local4 != this.m_level){
                this.m_level = _local4;
            };
            var _local8:MovieClip = (this.m_xpSlider.sliderMask as MovieClip);
            var _local9:Number = Number(_local3[(Global.player.level - 1)].@requiredXP);
            var _local10:Number = Number(_local3[(_local4 - 1)].@requiredXP);
            if (Global.player.level == _local3.length()){
                _local7 = 0;
                _local5 = 0;
                m_toolTip.toolTip = ZLoc.t("Main", "XP_ToolTip", {
                    experience:_local7,
                    level:Global.player.level
                });
            } else {
                if (_local9 > _local10){
                    _local7 = (Number(_local3[Global.player.level].@requiredXP) - _local2);
                    _local5 = (_local7 / _local3[Global.player.level].@requiredXP);
                    m_toolTip.toolTip = ZLoc.t("Main", "XP_ToolTip", {
                        experience:_local7,
                        level:(Global.player.level + 1)
                    });
                } else {
                    m_toolTip.toolTip = ZLoc.t("Main", "XP_ToolTip", {
                        experience:_local7,
                        level:(Global.player.level + 1)
                    });
                };
            };
            _local8.x = ((-(_local5) * _local8.width) + 5);
            var _local11:String = ((Global.player.level)<10) ? ("0" + Global.player.level.toString()) : Global.player.level.toString();
            this.m_levelText.setText(_local11);
            m_counter.value = _local2;
            this.m_xpText.setText(String(_local2));
        }

    }
}//package Display.hud.components 
